/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.CosBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.AttributeConstraint;
/*     */ import com.zimbra.cs.account.accesscontrol.TargetType;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetDelegatedAdminConstraints
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   private static final String CONSTRAINT_ATTR = "zimbraConstraint";
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  43 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  44 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  46 */     Entry entry = getEntry(request);
/*     */     
/*  48 */     AdminAccessControl.GetAttrsRight gar = new AdminAccessControl.GetAttrsRight();
/*  49 */     gar.addAttr("zimbraConstraint");
/*  50 */     checkRight(zsc, context, entry, gar);
/*     */     
/*  52 */     Map<String, AttributeConstraint> constraints = AttributeConstraint.getConstraint(entry);
/*     */     
/*  54 */     Element response = zsc.createElement(AdminConstants.GET_DELEGATED_ADMIN_CONSTRAINTS_RESPONSE);
/*     */     
/*     */ 
/*  57 */     boolean hasRequestedAttrs = false;
/*  58 */     for (Element a : request.listElements("a")) {
/*  59 */       hasRequestedAttrs = true;
/*     */       
/*  61 */       String attrName = a.getAttribute("name");
/*  62 */       AttributeConstraint ac = (AttributeConstraint)constraints.get(attrName);
/*  63 */       if (ac != null) {
/*  64 */         Element eAttr = response.addElement("a").addAttribute("name", attrName);
/*  65 */         ac.toXML(eAttr);
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*  70 */     if (!hasRequestedAttrs) {
/*  71 */       for (Map.Entry<String, AttributeConstraint> cons : constraints.entrySet()) {
/*  72 */         String attrName = (String)cons.getKey();
/*  73 */         AttributeConstraint ac = (AttributeConstraint)cons.getValue();
/*  74 */         Element eAttr = response.addElement("a").addAttribute("name", attrName);
/*  75 */         ac.toXML(eAttr);
/*     */       }
/*     */     }
/*     */     
/*  79 */     return response;
/*     */   }
/*     */   
/*     */   static Entry getEntry(Element request) throws ServiceException
/*     */   {
/*  84 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  86 */     String typeStr = request.getAttribute("type");
/*  87 */     TargetType type = TargetType.fromCode(typeStr);
/*     */     
/*  89 */     if (type == TargetType.config)
/*     */     {
/*  91 */       if (request.getAttribute("id", null) != null) {
/*  92 */         throw ServiceException.INVALID_REQUEST("cannot specify id for type " + typeStr, null);
/*     */       }
/*  94 */       if (request.getAttribute("name", null) != null) {
/*  95 */         throw ServiceException.INVALID_REQUEST("cannot specify name for type " + typeStr, null);
/*     */       }
/*  97 */       return prov.getConfig(); }
/*  98 */     if (type == TargetType.cos) {
/*  99 */       String id = request.getAttribute("id", null);
/* 100 */       String name = request.getAttribute("name", null);
/*     */       
/* 102 */       if (id != null) {
/* 103 */         Cos cos = prov.get(Key.CosBy.id, id);
/* 104 */         if (cos == null) {
/* 105 */           throw AccountServiceException.NO_SUCH_COS(id);
/*     */         }
/* 107 */         if ((name != null) && 
/* 108 */           (!name.equals(cos.getName()))) {
/* 109 */           throw ServiceException.INVALID_REQUEST("Specified name " + name + " does not match entry name for the specified id " + id, null);
/*     */         }
/*     */         
/* 112 */         return cos; }
/* 113 */       if (name != null) {
/* 114 */         Cos cos = prov.get(Key.CosBy.name, name);
/* 115 */         if (cos == null) {
/* 116 */           throw AccountServiceException.NO_SUCH_COS(name);
/*     */         }
/* 118 */         if ((id != null) && 
/* 119 */           (!id.equals(cos.getId()))) {
/* 120 */           throw ServiceException.INVALID_REQUEST("Specified id " + id + " does not match id for the specified name " + name, null);
/*     */         }
/*     */         
/* 123 */         return cos;
/*     */       }
/* 125 */       throw ServiceException.INVALID_REQUEST("neither id or name is specified", null);
/*     */     }
/*     */     
/* 128 */     throw ServiceException.INVALID_REQUEST("invalid type " + typeStr, null);
/*     */   }
/*     */   
/*     */ 
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 134 */     notes.add("Need set attr right on attribute zimbraConstraint");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetDelegatedAdminConstraints.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */